//index.js
//获取应用实例
const app = getApp();
// var template = require('../header/header.js');

Page({
    data: {
        radioList: [
            {name: '新房装修', value: 1},
            {name: '旧房翻新', value: 2},
        ],
        valueCurry: 0,
        optionList: [],
        optionIndex: 0,
    },
    onLoad: function () {
        this.getOption();
    },
    onHide: function () {
    },
    onChange: function (e) {
        let $dataset = e.currentTarget.dataset;
        this.setData({
            valueCurry: $dataset.index
        })
    },

    bindChange: function (e) {
        var index = e.detail.value;
        this.setData({
            optionIndex: index
        })
    },

    // 获取户型选项
    getOption: function() {
        var _this = this;
        var object = {
            url: app.api.url.other.houseList,
            success: function(res) {
                _this.setData({
                    optionList: res.data
                })
            }
        }
        app.request(object);
    },

    // 计算
    submit: function(e){
        var data = e.detail.value;
        var index = this.data.optionIndex;
        data.house_id = this.data.optionList[index]['id'];
        data.type = parseInt(this.data.valueCurry)+1;
        var object = {
            url: app.api.url.other.houseCalculator,
            data: data,
            success: function(res) {
                app.showToast(res.info);
            }
        }
        app.request(object);
    }
});
